<template>
	<view>
		<!-- <image class="logo" src="/static/logo.png"></image> -->
		<view class="text-area">
			<image src="/static/logo.png" style="width: 100%;height: 280px;"></image>
	    </view>
	    <view class="layout-form">
				<!-- <uni-search-bar placeholder="请输入姓名" cancel-text="cancel" cancelButton="none" bgColor="#EEEEEE" clearButton="auto" v-model="userName">
					<uni-icons slot="searchIcon" color="#999999" size="25" type="person"/>
				</uni-search-bar> -->
				<!-- <input class="uni-input"  placeholder="请输入姓名" v-model="userName"/> -->
			<view class="uni-logo">
				<uni-easyinput class="uni-input-logo" prefixIcon="person" placeholder="请输入工号" cancel-text="cancel" cancelButton="none" bgColor="#EEEEEE" clearButton="auto" v-model="userCode">
				</uni-easyinput>
			</view>
			<view class="uni-logo">
				<uni-easyinput  type="password" class="uni-input-logo" prefixIcon="locked" placeholder="请输入密码"  cancel-text="cancel" cancelButton="none" bgColor="#EEEEEE" clearButton="auto" v-model="userId">
				</uni-easyinput>
			</view>
			<view>
				<button type="primary" class="uni-button-color" @click="clickInter">登录</button>
			</view>
		</view>
		<view>
		</view>
		<!-- <view class="uni-btn">
			<span class="uni-left">
				<button class="mini-btn" type="primary" @click="clickInter">登录</button>
			</span>
			<span class="uni-right">
				<button class="mini-btn" type="default" plain="true">重置</button>
			</span>
		</view> -->
	</view>
</template>

<script>
	import { APIURL, post, postForm } from '../../utils/request.js';
	export default {
		data() {
			return {
				title: '程序名',
				userName: '',
				userCode: '',
				userId: ''
			}
		},
		onLoad() {
			
		},
		methods: {
			clickInter(){
				uni.showLoading({
					title: '登录中'
				});
				if(!this.userCode || !this.userId){
					uni.showToast({
						icon: 'none',
						title: '请输入工号、密码'
					});
					return;
				}
				const params = {
				        number: this.userCode,
				        password: this.userId
				      };
				  post('/user/login', params)
				        .then(data => {
							uni.hideLoading();
							console.log(data,'data')
							if(data.code == 200) {
							    uni.hideLoading();
								this.getUser(data.data)
							} else {
								uni.showToast({
								  icon: 'none',
								  title: '登录失败，请检查正确用户信息！'
								});
							}
				        })
				        .catch(err => {
						  uni.hideLoading();
				          uni.showToast({
				            icon: 'none',
				            title: '登录失败，请检查接口返回'
				          });
				        });
			},
			getUser(userId) {
						  uni.hideLoading();
				postForm('/user/selectById', {id: userId} )
				    .then(data => {
						if(data.code == 200) {
							let userInfor = data.data
							userInfor.userId = userId,
							uni.setStorageSync('userInfor', userInfor);
							if(userInfor.isRectify == true) {
								uni.switchTab({
								    url: '/pages/work/index'
								});
							} else {
								uni.switchTab({
								    url: '/pages/index/index'
								});
							}
							
						} else {
							  uni.showToast({
							    icon: 'none',
							    title: "查询用户信息失败，请检查接口返回！"
							  });
						}
				    })
				    .catch(err => {
				        uni.showToast({
				           icon: 'none',
				          title: '获取数据失败，请检查接口返回'
				        });
				    });
			}
		}
	}
</script>

<style>
	.uni-button-color {
		background-color: #007aff !important;
		font-size: 17px !important;
	}
	.uni-logo {
		width: 100%;
		text-align: center;
		margin-bottom: 20px;
	}
	.is-input-border {
		height: 43px;
	}
	element.style {
	    border-radius: 5px;
	    background-color: #EEEEEE;
	}
	.uni-input-logo {
	    display: flex;
	    box-sizing: border-box;
	    justify-content: left;
	    overflow: hidden;
	    position: relative;
	    flex: 1;
	    flex-direction: row;
	    align-items: center;
	    height: 43px !important;
	    padding: 5px 8px 5px 0px;
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.text-area{
	}
	.layout-form {
		text-align: center;
		padding: 0 20px;
		margin-top: 30px;
	}
	.form-type-input {
		text-align: left;
		font-size: 12px;
	}
	.form-type {
		font-size: 12px;
		width: 60%;
		
	}
	.layout-form-item {
		padding: 30px 0;
		display: flex;
	}
	.form-label {
		width: 40%;
		font-size: 14px;
		color: #000;
	}
	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
		}
	.text-area {
		display: flex;
		justify-content: center;
	}
	.uni-btn{
		margin-top: 20px;
		text-align: center;
		width: 100%;
	}
	.mini-btn{
		display: inline;
		width: 50%;
	}
	.uni-left{
		text-align: center;
		width: 50%;
		display: inline-block;
	}
	.uni-right{
		text-align: center;
		width: 50%;
		display: inline-block;
	}
	.title {
		font-size: 36rpx;
		color: #ffffff;
	}
</style>
